#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2020-08-27 14:55:42
# @Author  : Zuo Zhongfei (zuozhongfei@126.com)
# @Link    : www
# @Version : $Id$

import os

# 分析文本
# 使用split（） 函数把一句话分析成一个包含所有单词的数组
title = "Alice in Wonderland"
titleList = title.split()
print(titleList)

# 分析整个alice.txt文件
filename = '../../file/chapter_10/alice.txt'
try:
    with open(filename) as file_object:
        contents = file_object.read()
except FileNotFoundError as e:
    msg = "Sorry, the file " + filename + " does not exist"
    print(msg)
else:
    # 计算文件包含多少个单词
    words = contents.split()
    num_words = len(words)
    print("The file " + filename + ' has about ' + str(num_words) + ' words')
    # for word in words:
    #     print(word)
